﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

using Telerik.WinControls;
using Telerik.WinControls.UI;
using Telerik.WinControls.UI.Docking;

namespace UnigenReport
{
    public partial class fMain : Telerik.WinControls.UI.RadRibbonForm
    {
        #region Khởi tạo

        public fMain()
        {
            InitializeComponent();
            SetEvent();
        }

        private void SetEvent()
        {
            this.Load += OnLoad;
            this.btnLogOut.Click += new System.EventHandler(this.btnLogOut_Click);
            this.btnHelp.Click += new System.EventHandler(this.btnHelp_Click);
            this.btnAero.Click += new System.EventHandler(this.btnAero_Click);

            this.btnAccMan.Click += new System.EventHandler(this.btnAccMan_Click);
            this.btnChangePass.Click += new System.EventHandler(this.btnChangePass_Click);

            this.btnShippingRequest.Click += new System.EventHandler(this.btnShippingRequest_Click);
            this.btnWO.Click += new System.EventHandler(this.btnWO_Click);
            this.btnInvoice.Click += new System.EventHandler(this.btnInvoice_Click);

            this.btnProduct.Click += new System.EventHandler(this.btnProduct_Click);
            this.btnPackingStandard.Click += new System.EventHandler(this.btnPackingStandard_Click);
            this.btnCartonType.Click += new System.EventHandler(this.btnCartonType_Click);
            this.btnPalletStandard.Click += new System.EventHandler(this.btnPalletStandard_Click);
            this.btnShipAddress.Click += new System.EventHandler(this.btnShipAddress_Click);
            this.btnShipAccount.Click += new System.EventHandler(this.btnShipAccount_Click);
            this.btnShipVia.Click += new System.EventHandler(this.btnShipVia_Click);
            this.btnShipTerm.Click += new System.EventHandler(this.btnShipTerm_Click);
            this.btnUnit.Click += new System.EventHandler(this.btnUnit_Click);
        }

        private void OnLoad(object sender, EventArgs e)
        {
            if (Variables.UserName.ToUpper() != "ADMIN")
            {
                btnAero.Visibility = ElementVisibility.Collapsed;
                if (Variables.UserType != 0)//KO phải quản trị thì ko đc thêm user
                {
                    gbtnAccMan.Visibility = ElementVisibility.Collapsed;
                }

                switch (Variables.UserRoleID)
                {
                    case 1: //Chỉ tạo sr
                        {
                            gbtnWO.Visibility = ElementVisibility.Collapsed;
                            gbtnInvoice.Visibility = ElementVisibility.Collapsed;
                            pnlList.Visibility = ElementVisibility.Collapsed;
                            btnShippingRequest_Click(null, null); 

                            break;
                        }
                    case 2: //Xác nhận sr
                        {
                            gbtnWO.Visibility = ElementVisibility.Collapsed;
                            gbtnInvoice.Visibility = ElementVisibility.Collapsed;
                            pnlList.Visibility = ElementVisibility.Collapsed;
                            btnShippingRequest_Click(null, null); 

                            break;
                        }
                }
            }
        }

        #endregion

        #region Hàm

        private void AddPage(string name, string text, UserControl uc)
        {
            try
            {
                //Khai báo page
                var accManView = new RadPageViewPage();
                accManView.Name = name;
                accManView.Text = text;
                accManView.Controls.Add(uc);

                //Add vào form
                if (pageMan.Pages[name] == null) //Nếu chưa tồn tại mới add
                    pageMan.Pages.Add(accManView);

                //Chọn tab
                pageMan.Pages.ChangeIndex(pageMan.Pages[name], 0);
                pageMan.SelectedPage = pageMan.Pages[name];
            }
            catch (Exception ex)
            {
                Common.ShowErrorMess("AddPage - " + ex.Message);
            }
        }

        #endregion

        #region Sự kiện

        #region Top button

        private void btnAero_Click(object sender, EventArgs e)
        {
            //Mở form query
            fQuery fQuery = new fQuery();
            fQuery.StartPosition = FormStartPosition.CenterScreen;
            fQuery.ShowDialog();
        }

        private void btnHelp_Click(object sender, EventArgs e)
        {
            
        }

        private void btnLogOut_Click(object sender, EventArgs e)
        {
            if (Common.ShowQuestion("Bạn có chắc chắc đăng xuất?") == System.Windows.Forms.DialogResult.OK)
            {
                this.Dispose();
            }
        }
        
        #endregion

        #region Ribbon button
        
        private void btnAccMan_Click(object sender, EventArgs e)
        {
            AddPage("ucAccount", "Account", new Form.ucAccount() { Dock = DockStyle.Fill });
        }

        private void btnChangePass_Click(object sender, EventArgs e)
        {
            AddPage("ucChangePass", "Change Password", new Form.ucChangePass() { Dock = DockStyle.Fill });
        }

        private void btnShippingRequest_Click(object sender, EventArgs e)
        {
            AddPage("ucShippingRequest", "Shipping Request", new Form.ucShippingRequest() { Dock = DockStyle.Fill });
        }

        private void btnWO_Click(object sender, EventArgs e)
        {
            AddPage("ucWorldOrder", "WO Management", new Form.ucWorldOrder() { Dock = DockStyle.Fill });
        }

        private void btnInvoice_Click(object sender, EventArgs e)
        {
            AddPage("ucInvoice", "Invoices", new Form.ucInvoice() { Dock = DockStyle.Fill });
        }
        
        private void btnProduct_Click(object sender, EventArgs e)
        {
            AddPage("ucProduct", "Products", new Form.ucProduct() { Dock = DockStyle.Fill });
        }

        private void btnPackingStandard_Click(object sender, EventArgs e)
        {
            AddPage("ucPackingStandard", "Packing Standard", new Form.ucPackingStandard() { Dock = DockStyle.Fill });
        }

        private void btnCartonType_Click(object sender, EventArgs e)
        {
            AddPage("ucCartonType", "Carton Type", new Form.ucCartonType() { Dock = DockStyle.Fill });
        }

        private void btnPalletStandard_Click(object sender, EventArgs e)
        {
            AddPage("ucPalletStandard", "Pallet Standard", new Form.ucPalletStandard() { Dock = DockStyle.Fill });
        }

        private void btnShipAddress_Click(object sender, EventArgs e)
        {
            AddPage("ucShipAddress", "Ship Address", new Form.ucShipAddress() { Dock = DockStyle.Fill });
        }

        private void btnShipAccount_Click(object sender, EventArgs e)
        {
            AddPage("ucShipAccount", "Ship Account", new Form.ucShipAccount() { Dock = DockStyle.Fill });
        }

        private void btnShipVia_Click(object sender, EventArgs e)
        {
            AddPage("ucShipVia", "Ship Via", new Form.ucShipVia() { Dock = DockStyle.Fill });
        }

        private void btnShipTerm_Click(object sender, EventArgs e)
        {
            AddPage("ucShipTerm", "Ship Term", new Form.ucShipTerm() { Dock = DockStyle.Fill });
        }

        private void btnUnit_Click(object sender, EventArgs e)
        {
            AddPage("ucUnit", "Unit", new Form.ucUnit() { Dock = DockStyle.Fill });
        }
        
        #endregion

        #endregion
    }
}
